package com.epalmpay.controller.channel.trade;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.epalmpay.commom.BaseController;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.system.PageDTO;
import com.epalmpay.dto.trade.MemberUploadRecordInDTO;
import com.epalmpay.dto.trade.MemberUploadRecordListOutDTO;
import com.epalmpay.dto.trade.MemberUploadRecordOutDTO;
import com.epalmpay.entity.Page;
import com.epalmpay.entity.TradeUpload;
import com.epalmpay.service.trade.IMemberUploadRecordService;
import com.epalmpay.util.PropertyCopyUtil;
import com.epalmpay.util.Tools;

/**
 * Created by wucongpeng on 2017/5/7.
 */
@Controller
@RequestMapping(value = "/channel/device")
public class DeviceMemberUploadRecordController extends BaseController {

    @Resource
    private IMemberUploadRecordService memberUploadRecordService;

    /**
     * 显示线下交易记录分页列表
     * @param memberUploadRecordInDTO
     * @param pageDTO
     * @return
     */
    @RequestMapping(value = "/memberUploadRecordList")
    @ResponseBody
    public MemberUploadRecordListOutDTO listMemberUploadRecord(MemberUploadRecordInDTO memberUploadRecordInDTO, PageDTO pageDTO) {
        MemberUploadRecordListOutDTO memberUploadRecordListOutDTO = new MemberUploadRecordListOutDTO();
        ArrayList<MemberUploadRecordOutDTO> memberUploadRecordOutDTOs = new ArrayList<MemberUploadRecordOutDTO>();
        try {

            Page page = Tools.pageEmtity(pageDTO);


            List<TradeUpload> list = memberUploadRecordService.listMemberUploadRecords(memberUploadRecordInDTO, page);

            for (int i = 0; i < list.size(); i++){
                MemberUploadRecordOutDTO dtos = new MemberUploadRecordOutDTO();
                PropertyCopyUtil.copyPropertiesExclude(list.get(i), dtos,"memberInfo","merchantShop","activityBase","joinStart", "joinEnd");

                dtos.setMerchantName(list.get(i).getMerchantName());
                dtos.setActivityName(list.get(i).getActivityName());
                dtos.setMemberName(list.get(i).getMemberName());

                memberUploadRecordOutDTOs.add(dtos);
                memberUploadRecordListOutDTO.setMemberUploadRecordOutDTOList(memberUploadRecordOutDTOs);
            }

            memberUploadRecordListOutDTO.setPage(page);
            memberUploadRecordListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");

            return memberUploadRecordListOutDTO;

        } catch (ApplicationException ae) {
            memberUploadRecordListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            memberUploadRecordListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return memberUploadRecordListOutDTO;
    }


    @RequestMapping(value = "/updateAuditStatusList")
    @ResponseBody
    public List<Integer> updateAuditStatusList(@RequestBody List<MemberUploadRecordInDTO> memberUploadRecordInDTOList) {
        return memberUploadRecordService.updateAuditStatus(memberUploadRecordInDTOList);

    }
}





















